Conversation
jcheroske
left a comment
There was a problem hiding this comment.
You're doing great, Mike!
| const getActiveUsers = (data) => { | ||
| if (data == null || data.users == null) { | ||
| return null | ||
| } else { |
There was a problem hiding this comment.
You can get rid of the else block and it will make your code easier to read.
| } else { | ||
| const activeUsers = [] | ||
| data.users.forEach((u) => { | ||
| if (u.accountActive === true) { |
There was a problem hiding this comment.
Since u.accountActive is a boolean, you can shorten your test to:
if (u.accountActive)
| const getMostExpensiveProduct = (data) => { | ||
| if (data == null || data.products == null) { | ||
| return null | ||
| } else { |
There was a problem hiding this comment.
This else block can be eliminated as well.
| if (data == null || data.orders == null) { | ||
| return null | ||
| } else { | ||
| const orders = [] |
There was a problem hiding this comment.
Since we've already got data.orders, and since the function is called getOrderInto, lets call this array orderInfos instead.
| if (data == null || data.products == null || id == null) { | ||
| return null | ||
| } else { | ||
| return data.products.find((p) => p.id === id) |
There was a problem hiding this comment.
When your lambda function only takes one parameter, you can eliminate the parens if you want. I find it makes the code easier to read:
p => p.id === id
Your call on that one though.
| throw new Error('Do not have data or ID') | ||
| } | ||
| const order = data.orders.find((o) => o.id === id) | ||
| if (order === undefined) { |
There was a problem hiding this comment.
Testing for undefined is usually not recomended. It's more of a style thing. I would do one of these tests instead:
if (!order) {
or
if (order == null) {
| @@ -0,0 +1,18 @@ | |||
| import getProductById from './getProductById' | |||
There was a problem hiding this comment.
Notice how similar this function (getTotalPriceForOrder) is to getProductsForOrder. Can you import that function and use it to get the total price?
|
You created your |
No description provided.